
from file_system import FileSystem

class FileSystemOS(object):
    def __init__(self):
        self.__file_systems = {}

    def contains(self, name: str) -> bool:
        return name in self.__file_systems

    def register_file_system(self, fs_type: FileSystem) -> bool:
        name = fs_type.get_name()
        if self.contains(name):
            return False
        self.__file_systems[name] = fs_type
        return True

    def unregister_file_system(self, name: str):
        if self.contains(name):
            del self.__file_systems[name]

    def get_file_system(self, name: str) -> FileSystem | None:
        if self.contains(name):
            return self.__file_systems[name]
        return None
    
    def __repr__(self):
        r = ""
        for (k, v) in self.__file_systems.items():
            r = r + f"{k}:{v}, "
        return r

    """
    def mount(self, dev_path: str, mnt_p: str, tp: str, flags: int, data: object):
        pass
    def umount(self, mnt_p: str, flags: int):
        pass

    def open(self):pass
    def read(self):pass
    def write(self):pass
    def close(self):pass
    """



import unittest
class TestApplication(unittest.TestCase):
    def test_main(self):
        fs_os = FileSystemOS()

        nm = "fat12"
        fs = FileSystem(nm)
        fs_os.register_file_system(fs)
        print(f"after register :[{fs_os}]")

        fs_fat12 = fs_os.get_file_system(nm)
        self.assertEqual(fs, fs_fat12)

        fs_os.unregister_file_system(nm)
        self.assertIsNone(fs_os.get_file_system(nm))
        print(f"after unregister :[{fs_os}]")
        

